import * as Router from 'koa-router';

const router = new Router();
router.prefix('/api/shanbay')

import Shanbay from '../controller/shanbay/Shanbay';

router.get('/', function (ctx, next) {
  ctx.body = '扇贝1'
})

router.post('/addword', async function (ctx, next) {
  const body = ctx.request.body as any;
  const data = {
    token: body.token,
    word: body.word
  }

  try {
    ctx.body = await Shanbay.addWord(data.token, data.word);
  } catch (e) {
    ctx.body = e;
  }

  next();
})

router.get('/getsetting', async function (ctx, next) {
  try {
    ctx.body = await Shanbay.getSetting();
  } catch (e) {
    ctx.body = e;
  }

  next();
})

export default router
